//
//  UIView+LZExtension.m
//  百思不得姐
//
//  Created by 郝庆 on 16/5/11.
//  Copyright © 2016年 haoqing. All rights reserved.
//

#import "UIView+LZExtension.h"

@implementation UIView (LZExtension)
- (CGSize)lz_size
{
    return self.frame.size;
}

- (void)setLz_size:(CGSize)lz_size
{
    CGRect frame = self.frame;
    frame.size = lz_size;
    self.frame = frame;
}

- (CGFloat)lz_width
{
    return self.frame.size.width;
}

- (CGFloat)lz_height
{
    return self.frame.size.height;
}

- (void)setLz_width:(CGFloat)lz_width
{
    CGRect frame = self.frame;
    frame.size.width = lz_width;
    self.frame = frame;
}

- (void)setLz_height:(CGFloat)lz_height
{
    CGRect frame = self.frame;
    frame.size.height = lz_height;
    self.frame = frame;
}

- (CGFloat)lz_x
{
    return self.frame.origin.x;
}

- (void)setLz_x:(CGFloat)lz_x
{
    CGRect frame = self.frame;
    frame.origin.x = lz_x;
    self.frame = frame;
}

- (CGFloat)lz_y
{
    return self.frame.origin.y;
}

- (void)setLz_y:(CGFloat)lz_y
{
    CGRect frame = self.frame;
    frame.origin.y = lz_y;
    self.frame = frame;
}

- (CGFloat)lz_centerX
{
    return self.center.x;
}

- (void)setLz_centerX:(CGFloat)lz_centerX
{
    CGPoint center = self.center;
    center.x = lz_centerX;
    self.center = center;
}

- (CGFloat)lz_centerY
{
    return self.center.y;
}

- (void)setLz_centerY:(CGFloat)lz_centerY
{
    CGPoint center = self.center;
    center.y = lz_centerY;
    self.center = center;
}

- (CGFloat)lz_right
{
    return CGRectGetMaxX(self.frame);
}

- (CGFloat)lz_bottom
{
    return CGRectGetMaxY(self.frame);
}

- (void)setLz_right:(CGFloat)lz_right
{
    self.lz_x = lz_right - self.lz_width;
}

- (void)setLz_bottom:(CGFloat)lz_bottom
{
    self.lz_y = lz_bottom - self.lz_height;
}

+ (instancetype)lz_viewFromXib
{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (BOOL)lz_intersectWithView:(UIView *)view
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGRect selfRect = [self convertRect:self.bounds toView:window];
    CGRect viewRect = [view convertRect:view.bounds toView:window];
    return CGRectIntersectsRect(selfRect, viewRect);
}

@end
